/*
 * CountingMgr.h
 *
 *  Created on: Oct 19, 2011
 *      Author: kimi
 */

#ifndef COUNTINGMGR_H_
#define COUNTINGMGR_H_
#include "../FLR/FLRFile.h"
#include "../Hash/ExtensibleHash.h"
#include <string>
#include "../../Model/Eleccion.h"
#include "Count.h"
#include "../../Utils/StringUtils.h"

using namespace std;

class CountingMgr {

public:
	CountingMgr(string filePath);
	virtual ~CountingMgr();

	bool createCountingRegistersForEleccion(Eleccion *eleccion);

	bool incrementCountOnRegister(unsigned long eleccionId, unsigned long distritoId, unsigned long listaId);

	vector<Count> getCountFilteredByEleccion(unsigned long eleccionId);
	vector<Count> getCountFilteredByLista(unsigned long listaId);
	vector<Count> getCountFilteredByDistrito(unsigned long distritoId);

	bool addListaEnEleccion(unsigned long eleccionId, unsigned long listaId,string nombreLista);
	vector<unsigned long>getListasParaEleccion(unsigned long eleccionId);

	bool addListaToListaSimilar(string nombre, unsigned long listId);
	vector<unsigned long>getListasIDsParaLista(string nombre);

private:
	FLRFile* countingFile;

	ExtensibleHash* eleccionesHash; //key = idEleccion; value = posicion de donde empieza el registro en countingFile

	ExtensibleHash* listasEnElecciones;// key = idEleccion; value = lista de elecciones

	ExtensibleHash* filtroDistritos; // key = idDistrito; value = listas de recordId de conteos
	ExtensibleHash* filtroListas; // key = idLista; value = listas de recordId de listas
	ExtensibleHash* filtroElecciones; // key = idEleccion; value = listas de recordId de elecciones

	ExtensibleHash* listasConIgualNombre; //key = idListaConvertido ; values = ids listas

	unsigned long tamanioGenericoDeRegistros;

	bool addIdToFiltroDistrito(unsigned long distritoId, unsigned long id);
	bool addIdToFiltroLista(unsigned long listaId, unsigned long id);
	bool addIdToFiltroEleccion(unsigned long eleccionId, unsigned long id);
};

#endif /* COUNTINGMGR_H_ */
